package com.tl.khadmin.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.tl.khadmin.bean.OrderAftersale;
import com.tl.khadmin.bean.OrderException;
import com.tl.khadmin.bean.Supplier;
import com.tl.khadmin.bean.OrderAftersale;
import com.tl.khadmin.page.Page;
import com.tl.khadmin.service.OrderAftersaleIService;
import com.tl.khadmin.service.OrderAftersaleIService;
import com.tl.khadmin.util.CommonUtil;

/**
 * 订单售后信息
 * @author 123
 */
@RequestMapping(value = "/order/aftersale")
@RestController
public class OrderAftersaleController {
	
	@Resource
	private OrderAftersaleIService orderAftersaleService; 
	
	@RequestMapping(value = "/querybyid")
	@ResponseBody
	public Map<String, Object> querybyId(HttpSession session, Integer id) {
		if(id == null){
			return null;
		}
		return orderAftersaleService.querybyId(id);
	}
	
	/**
	 * 上传售后图片
	 * @param session
	 * @param file
	 * @return
	 */
	@RequestMapping(value="/uploadaftersaleimg")  
	@ResponseBody
	public Map<String, String> upLoadAftersaleImg(HttpSession session, @RequestParam("file") MultipartFile file){
		String path = session.getServletContext().getRealPath("/upload/productimg");
		return orderAftersaleService.upLoadAftersaleImg(path,file); 
	}
	
	
	/**
	 * 保存订单异常信息
	 * @param orderException
	 * @return
	 */
	@RequestMapping(value = "/save")
	@ResponseBody
	public String saveOrderAftersale(HttpSession session, OrderAftersale orderAftersale){
		return orderAftersaleService.saveOrderAftersale(session, orderAftersale);
	} 
	
	@RequestMapping(value = "/detail")
	@ResponseBody
	public Map<String, Object> queryDetailById(Integer id) {
		if(id == null){
			return null;
		}
		return orderAftersaleService.queryDetailById(id);
	}
	
	/**
	 * 客服审核售后订单
	 * @param session
	 * @param orderAftersale
	 * @return
	 */
	@RequestMapping(value = "/deal") 
	@ResponseBody
	public String deal(HttpSession session, OrderAftersale orderAftersale) {
		return orderAftersaleService.deal(session, orderAftersale);
	}
	
	/**
	 * 客服审核售后订单
	 * @param session
	 * @param orderAftersale
	 * @return
	 */
	@RequestMapping(value = "/serviceaudit") 
	@ResponseBody
	public String serviceAudit(HttpSession session, OrderAftersale orderAftersale) {
		return orderAftersaleService.serviceAudit(session, orderAftersale);
	} 
	
	/**
	 * 供应商审核售后订单
	 * @param session
	 * @param orderAftersale
	 * @return
	 */
	@RequestMapping(value = "/supplieraudit") 
	@ResponseBody
	public String supplierAudit(HttpSession session, OrderAftersale orderAftersale) {
		return orderAftersaleService.supplierAudit(session, orderAftersale);
	} 
	
	
	
	/**
	 * @param param level：查询快递公司列表
	 * @param param OrderAftersaleName：名称，模糊查询
	 * @param param status：1启用，2禁用
	 * @return
	 */
	@RequestMapping(value="/list") 
	public Map<String, List<OrderAftersale>> listOrderAftersale(@RequestParam Map<String ,Object> param){
		return CommonUtil.returnResultCodeJson("orderAftersale", orderAftersaleService.listOrderAftersale(param));
	}

	@RequestMapping(value = "/showbypage")
	public Map<String, Page<OrderAftersale>> showProductBrandByPage(HttpSession session, @RequestParam Map<String, Object> params) { 
		Integer pageNum = Integer.parseInt(params.get("pageNum").toString());
		Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
		return CommonUtil.returnResultCodeJson("result", 
				orderAftersaleService.showOrderAftersaleByPage(session, pageNum, pageSize, params));
	}
}
